﻿using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;

namespace SelfService.Model.Models;


public class SysTask : TopBasePoco
{
    [Display(Name = "名称")]
    [StringLength(128)]
    [Required]
    public string Name { get; set; }

    [Display(Name = "类名")]
    [StringLength(128)]
    [Required]
    public string ClassName { get; set; }
        
    [Display(Name = "任务类型")]
    [Required]
    public TaskTypeEnum TaskType { get; set; }

    [Display(Name = "上次运行开始时间")]
    public DateTime? LastRunTime { get; set; }
        
    [Display(Name = "上次运行结束时间")]
    public DateTime? LastEndTime { get; set; }
        
    [Display(Name = "下次运行时间")]
    public DateTime? NextRunTime { get; set; }

    [DisplayName("时间类型")]
    public TimeTypeEnum TimeType { get; set; }
    
    /// <summary>
    /// 运行间隔
    /// 周期任务需调用此参数; 定时任务需按照时间单位+此参数; 单次任务无需次参数;
    /// </summary>
    [DisplayName("运行间隔")]
    public TimeSpan Interval { get; set; }
        
    [Display(Name = "上次运行状态")]
    public  TaskResultEnum? LastRunResult{ get; set; }

    [DisplayName("创建时间")]
    [Required]
    public DateTime CreateTime { get; set; }
    
    [Display(Name = "是否启用")]
    [Required]
    public bool IsEnable { get; set; }

    [Display(Name = "是否运行")]
    [Required]
    public bool IsRun { get; set; }
}


public enum TaskTypeEnum
{
    单次任务 = 0,
    周期任务 = 10,
    定时任务 = 20,
}

public enum TaskResultEnum
{
    初始化,
    失败,
    成功
}

public enum TimeTypeEnum
{
    天,
    周,
    月,
    年
}
